package org.tln.db137.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.tln.db137.common.R;
import org.tln.db137.entity.Rolemenu;
import org.tln.db137.service.RoleService;
import org.tln.db137.service.RolemenuService;

import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin("*")
public class RoleMenuController {
    @Autowired
    private RolemenuService rolemenuService;

    @GetMapping("selectrmId/{roleid}")
    public R selectrmId(@PathVariable("roleid") int roleid) {
        QueryWrapper<Rolemenu> wrapper = new QueryWrapper<>();
        wrapper.eq("roleid", roleid);
        List<Rolemenu> rolemenuList = this.rolemenuService.list(wrapper);
        return new R().add("rolemenuList", rolemenuList);
    }

    /**
     * 根据角色id修改角色对应的菜单id集合
     * @return
     */
    @PostMapping("/updateRoleMenuid")
    public R updateRoleMenuid(@RequestBody Map<String,Object> map){
        int roleid = Integer.parseInt(map.get("roleid").toString());
        List<Integer> listMenu=(List<Integer>) map.get("listMenu");
        System.out.println("roleid = " + roleid);
        System.out.println("listMenu = " + listMenu);
        boolean boo=rolemenuService.updateRoleMenuid(roleid,listMenu);
        return new R();
    }
}
